$(document).ready(function() {
	$.globalVars = {
		originalTop: 0,
		originalLeft: 0,
		maxHeight: $("#draggable").height() - $(".bdLimit").height(),
		maxWidth: $("#draggable").width() - $(".bdLimit").width()
	};
	$("#draggable").draggable({		
		cursor: 'move',
		start: function(event, ui) {			
			if (ui.position != undefined) {				
				$.globalVars.originalTop = ui.position.top;
				$.globalVars.originalLeft = ui.position.left;
			}
		},
		drag: function(event, ui) {
			$('#canvas').hide();
			var newTop = ui.position.top;
			var newLeft = ui.position.left;
			if (ui.position.top < 0 && ui.position.top * -1 > $.globalVars.maxHeight) {
				newTop = $.globalVars.maxHeight * -1;
			}
			if (ui.position.top > 0) {
				newTop = 0;
			}
			if (ui.position.left < 0 && ui.position.left * -1 > $.globalVars.maxWidth) {
				newLeft = $.globalVars.maxWidth * -1;
			}
			if (ui.position.left > 0) {
				newLeft = 0;
			}
			ui.position.top = newTop;
			ui.position.left = newLeft;
		},
		stop: function(event, ui) {
			var xPos = 0;
			var yPos = Math.abs(ui.position.top);	
			var tPos = ui.position.top;			
			$('#canvas').show();
			$('#canvas').html('<span>Đang lưu vị trí, bạn vui lòng chờ trong giây lát.</span>');				
			/*$.getJSON(				
				HOST_VFRIEND + 'ajax/cover?coverid='+intCoverId+'&xc='+xPos+'&yc='+yPos+'&top='+tPos+'&callback=?',		
				function(response) {
					$('#ptop').val(tPos);	
				}
			);*/			
		}
	});	
});
